/*头部下拉*/
$.fn.headmenu = function(type){
	var self = $(this),list;
	if(type === 1){
		list = self.find('.menu');
	}else{
		list = self;
	}
	list.hover(function(){
		$(this).toggleClass('hover').find('.sub_menu').toggleClass('hide');
	});
}

/*总分类显隐*/
$.fn.Prolist = function(){
	var self = $(this);
	var curName = 'cur';
	self.delegate('.item','hover',function(){
		$(this).toggleClass("cur");
	});
}
/*订单详情*/
$.fn.OrderInfo = function(){
	var self = $(this);
	self.delegate('.item','hover',function(){
		$(this).parent().toggleClass("hover");
	});
}
/*新增修改收货地址*/
$.fn.Address = function(){
	var self = $(this);
	var obj = self.find(".click");
	var tabs = self.find(".address_from");
	var clos = tabs.find(".ico_close");
	obj.click(function(){
		tabs.removeClass("hide");
		tabs.addClass("open");
	});
	clos.click(function(){
		tabs.removeClass("open");
		tabs.addClass("hide");
	});
}
/*tab*/
$.fn.TabADS = function(){
	var obj = $(this);
	var currentClass = "select";
	var tabs = obj.find(".tab_hd").find("li");
	var conts = obj.find(".tab_cont");
	var t;
	tabs.eq(0).addClass(currentClass);
	conts.hide();
	conts.eq(0).show();
	tabs.each(function(i){
		$(this).bind("mouseover",function(){
			 t = setTimeout(function(){
				conts.hide().eq(i).show();
				tabs.removeClass(currentClass).eq(i).addClass(currentClass);
			},200);
		}).bind("mouseout",function(){
			clearTimeout(t);
		});
	});
}
/*tab2*/
$.fn.TabADS2 = function(){
	var obj = $(this);
	var currentClass = "select";
	var tabs = obj.find(".tab_hd2").find("li");
	var conts = obj.find(".tab_cont2");
	var t;
	tabs.eq(0).addClass(currentClass);
	conts.hide();
	conts.eq(0).show();
	tabs.each(function(i){
		$(this).bind("click",function(){
			 conts.hide().eq(i).show();
			tabs.removeClass(currentClass).eq(i).addClass(currentClass);
		});
	});
}
/*tab3*/
$.fn.TabADS3 = function(){
	var obj = $(this);
	var currentClass = "select";
	var tabs = obj.find(".tab_hd").find(".radio");
	var conts = obj.find(".tab_cont");
	var t;
	tabs.eq(0).addClass(currentClass);
	conts.hide();
	conts.eq(0).show();
	tabs.each(function(i){
		$(this).bind("click",function(){
			 conts.hide().eq(i).show();
			tabs.removeClass(currentClass).eq(i).addClass(currentClass);
		});
	});
}
/*商铺收藏*/
$.fn.TabADS4 = function(){	
	var obj = $(this);	
	var tabs = obj.find(".item").find(".show");
	var conts = obj.find(".tab_cont");		
	conts.hide();	
	tabs.toggle(function(){		 
		 $(this).parent().parent().siblings(".tab_cont").show();
		 $(this).addClass("select");
		},
	function(){
		$(this).parent().parent().siblings(".tab_cont").hide();
		$(this).removeClass("select");
	});	 
}
/*二级页分类列表*/
$.fn.Subsort = function(){
	var self = $(this);
	self.delegate('.click','click',function(event){
		$(this).parent().toggleClass('open');
		event.preventDefault();
	});
}

$.fn.Subsort2 = function(){
	var self = $(this);
	self.delegate('.click2','click',function(event){
		$(this).parent().parent().toggleClass('open');
		event.preventDefault();
	});
}

/*查看更多搜索项*/
$.fn.showMore = function(){
	var self = $(this),txt='打开';
	var a = self.find('.other a');
	if(a.length < 10){self.next().find('.c_06c').hide();return;}
	a.filter(':gt(10)').addClass('hide');
	self.next().find('.c_06c').bind('click',function(event){
		txt = $(this)[0].className.indexOf('sq')>0?'更多':'收起';
		$(this).toggleClass('sq').text(txt);
		a.filter(':gt(10)').toggleClass('hide');
		event.preventDefault();
	});
}
/*详情页放大图片*/
function photoAlbum(node){
	var tab = node.find('.album_list'),
		tabs = tab.find('.item'),
		srcList = tabs.find('a'),
		bigPIC = node.find('#bigPIC'),
		imglink = '',
		superimgSRC = '',
		nowimglink = tab.find('.select').find('a').attr('href'),i = 0;
	var superPIC = $('#superPIC');
	tabs.hover(function(){
		i = tabs.index($(this));
		imglink = srcList.eq(i).attr('href');
		bigPIC.attr('src',imglink);
	},function(){
		
		bigPIC.attr('src',nowimglink);
	});
	tabs.bind('click',function(event){
		i = tabs.index($(this));
		imglink = srcList.eq(i).attr('href');
		superimgSRC = srcList.eq(i).attr('data-superbig');
		tabs.removeClass('select');
		$(this).addClass('select');
		bigPIC.attr('src',imglink);
		nowimglink = imglink;
		//超级大图
		superPIC.attr('src',superimgSRC);
		event.preventDefault();
	});
}

/*控制台侧导航*/
$.fn.Managenav = function(){
	var self = $(this);
	var obj = self.find(".cur")
	self.delegate('.item','hover',function(){
		$(this).toggleClass("hover");
		$(this).prev().toggleClass("no_bg");
	});
	obj.prev().toggleClass("no_bg");
}

function superIMG(node){
	var img = node.find('#bigPIC'),
		mask = node.find('#img_mask'),
		po = jQuery('#po_bigView'),
		superIMG = po.find('#superPIC'),
		offset = node.offset(),
		offset_x = offset.left,
		offset_y = offset.top;
	var superSRC = img.attr('data-superbig');
	superIMG.attr('src',superSRC);
	node.mousemove(function(event){
		mask.css('display','block');
		po.show();
		var mousex = event.pageX - offset_x;
		var mousey = event.pageY - offset_y;
		var mask_x = mousex-75;
		var mask_y = mousey-75;
		if(mask_x<0)mask_x = 0;
		if(mask_y<0)mask_y = 0;
		if(mask_x+150 > 332)mask_x = 184;
		if(mask_y+150 > 332)mask_y = 184;
		mask.css({'left':mask_x,'top':mask_y});
		po.css({'top':offset_y,'left':offset_x+348});
		superIMG.css({'left':-mask_x*2,'top':-mask_y*2});
	});
	mask.mouseout(function(){
		mask.css('display','');
		po.hide();
	});
}

function pro_sel(node1,node2){
	var list = node1.find('.item');
	var bigPIC = $('#bigPIC');
	var superPIC = $('#superPIC');
	var imgSRC='',superimgSRC='';
	node1.delegate('.item','click',function(event){
		node2.val($(this).attr('data-value'));
		list.removeClass('select');
		$(this).addClass('select');
		//切换颜色改变大图
		if(node1.attr('id') == "sel_color"){
			var a = $(this).find('a')
			imgSRC = a.attr('href');
			superimgSRC = a.attr('data-superbig')
			bigPIC.attr('src',imgSRC);
			//超级大图
			superPIC.attr('src',superimgSRC);
		}
		event.preventDefault();
	});
	
}

/*相册*/
function Album(node3){
	var tab = node3.find('.album_list'),
		tabs = tab.find('.item'),
		srcList = tabs.find('a'),
		bigPIC = node3.find('#bigPIC'),
		btnPrev = node3.find('#btnPrev')
		btnNext = node3.find('#btnNext')
		imglink = '',
		superimgSRC = '',
		nowimglink = tab.find('.select').find('a').attr('href'),i = 0;
	var superPIC = $('#superPIC');
	tabs.bind('click',function(event){
		i = tabs.index($(this));
		imglink = srcList.eq(i).attr('href');
		superimgSRC = srcList.eq(i).attr('data-superbig');
		tabs.removeClass('select');
		$(this).addClass('select');
		bigPIC.attr('src',imglink);
		nowimglink = imglink;
		//超级大图
		superPIC.attr('src',superimgSRC);
		event.preventDefault();
	});
	btnPrev.bind('click',function(event){
		for(var i= 0;i<srcList.length;i++){
		var tag = srcList[i];
		imglink = srcList.eq(i).attr('href');
		tabs.removeClass('select');
		$(tag).addClass('select');
		bigPIC.attr('src',imglink);
		nowimglink = imglink;
		}
		});
}
/*侧导航*/
$.fn.Cur = function(){
	var self = $(this);
	var curName = 'cur';
	var obj = self.find(".item");
	obj.click(function(){
		obj.removeClass("cur");
		$(this).addClass("cur"); 
	});
}
/*商家中心左则巴导航拆叠*/
$.fn.Subsort_c = function(){
	var self = $(this);
	self.delegate('.click','click',function(event){
		$(this).parent().parent().parent().toggleClass('open');
		event.preventDefault();
	});
}
/*分类管理*/
$.fn.TypeList = function(){
	var self = $(this);
	self.delegate('.ico_fold','click',function(event){
		$(this).parent().parent().parent().parent().toggleClass('open');
		event.preventDefault();
	});
}
/*宝贝归类*/
$.fn.ClassifyTab = function(){
	var self = $(this);
	self.delegate('.click','click',function(event){
		$(this).next().toggleClass('hide');
		$(this).parent().css('z-index','8');
		event.preventDefault();
	});
	self.delegate('.close','click',function(event){
		$(this).parent().toggleClass('hide');
		$(this).parent().parent().css('z-index','6');
		event.preventDefault();
	});
}
/*设置运费*/
$.fn.Fregihtset = function(){
	var self = $(this);
	self.delegate('.click','click',function(event){
		$(this).parent().prev().removeClass('hide');
		event.preventDefault();
	});
}
/*修改价格、库存*/
$.fn.Alterbox = function(){
	var self = $(this);
	self.delegate('.ico_edit','click',function(event){
		$(this).parent().addClass('showbox');
		event.preventDefault();
	});
	self.delegate('.ico_close','click',function(event){
		$(this).parent().parent().removeClass('showbox');
		event.preventDefault();
	});
}
/*
 * 多选操作
 * @param checkBoxName[]多选框名称
 * @param postUrl操作的地址
 * 操作将用AJAX传递
 * 接收操作用$_POST[checkBoxName]
 * */
function GetCheckbox(checkBoxName,postUrl){
    var data=new Array();
    var checkBox = checkBoxName+'[]';
    $("input:checkbox[name='"+checkBox+"']").each(function (){
        if($(this).attr("checked")==true){
               data.push($(this).val());
        }
    });
    if(data.length > 0){
            $.post(postUrl,{checkBoxName:data}, function (data) {
                    if (data=='ok') {
                            alert('删除成功！');
 							//window.open('index.php?r=ip/admin','indexFrame');;
                  	}
            });
    }else{
            alert("请选择要删除的选项!");
    }
}
/*拆叠列表*/
$.fn.FlodDown = function(){
	var self = $(this);
	self.delegate('.ico_fold','click',function(event){
		$(this).parent().parent().parent().toggleClass('open');
		event.preventDefault();
	});
}

/*全选
classs:被选框class
selfid：全选框id
*/
function checkAll(classs,selfid){
	$('.'+classs).attr('checked',$('#'+selfid).attr('checked')?'checked':false);
}

/*
 * 全选
 * @param e 全选选择框名称
 * @param itemName 单个选择框名称
 * */
function CheckAll(e,itemName)
{
	var allSelect=false;
	var allSelect2=true;
	var bb = document.getElementsByName(e);
	var aa = document.getElementsByName(itemName);
	for (var i=0; i<bb.length; i++){
    	if(bb[i].checked)  
    		allSelect=true;
    }
	for (var i=0; i<aa.length; i++){
    	if(!aa[i].checked)  
    		allSelect2=false;
    }
	if(allSelect&&allSelect2){
		allSelect = false;
	}
    if(allSelect){
	    for (var i=0; i<aa.length; i++)
	        aa[i].checked = true;
	    for (var i=0; i<bb.length; i++)
	    	bb[i].checked = true;
    }else{
    	for (var i=0; i<aa.length; i++)
	        aa[i].checked = false;   
    	for (var i=0; i<bb.length; i++)
	    	bb[i].checked = false;
    }
}
/*
 * 单选
 * @param e 全选选择框名称
 * @param itemName 单个选择框名称
 * */
function CheckList(e,itemName)
{
    var aa = document.getElementsByName(itemName);
    var bb = document.getElementsByName(e);
    var allSelect=true;
    for (var i=0; i<aa.length; i++){
    	if(!aa[i].checked)  allSelect=false;
    }
    if(allSelect){
    	for (var i=0; i<bb.length; i++)
    		bb[i].checked = true;
    }else{
    	for (var i=0; i<bb.length; i++)
    		bb[i].checked = false;
    }  
}

/*倒计时*/
function countdown(id){
	var time = $('#'+id).text();
	var D = Math.floor(time/(3600*24));//计算天数
	var H = Math.floor((time%(3600*24))/3600);//小时
	var I = Math.floor(((time%(3600*24))%3600)/60);//分钟
	var S = Math.floor((((time%(3600*24))%3600)%60)/60);//秒
	$('#'+id).text(D+'天'+H+'时'+I+'分'+S+'秒');
	$('#'+id).attr('val',time);
	setInterval('countdownauto("'+id+'")',1000);
}

/*倒计时自动变化*/
function countdownauto(id){
	var time = $('#'+id).attr('val');//alert(time);
	time--;
	var D = Math.floor(time/(3600*24));//计算天数
	var H = Math.floor((time%(3600*24))/3600);//小时
	var I = Math.floor(((time%(3600*24))%3600)/60);//分钟
	var S = Math.floor((((time%(3600*24))%3600)%60)%60);//秒
	$('#'+id).text(D+'天'+H+'时'+I+'分'+S+'秒');
	$('#'+id).attr('val',time);
}

 // 基于JQ的倒计时    
  $.fn.timeGo = function(options) {        
    var opts = $.extend({},$.fn.timeGo.defaults, options);         
    return this.each(function() { 													
      $this = $(this); 
      var sysSecond,interValObj;
	  var $mainSeconds=$(opts.mainSeconds,$this);
	  var $mainTime=$(opts.mainTimeShow,$this);
	  var $message=$(opts.message,$this);
	  var callBackFunction=opts.callBackFunction;
      sysSecond = parseInt($mainSeconds.html());
	  interValObj = window.setInterval(setRemainTime, 1000);
	  function setRemainTime()
	  {
         if (sysSecond > 0)
		 {
           sysSecond = sysSecond - 1;
           var second = Math.floor(sysSecond % 60);             // 计算秒
           var minite = Math.floor((sysSecond/60) % 60);      //计算分
           var hour = Math.floor((sysSecond / 3600) % 24);      //计算小时
           var day = Math.floor((sysSecond / 3600) / 24);        //计算天
           if (second>=0&&second<10) {second="0"+second};
           if (day>=0&&day<10) {day="0"+day};
           if (hour>=0&&hour<10) {hour="0"+hour};
           if (minite>=0&&minite<10) {minite="0"+minite};
           $mainTime.html("<span class=' day'>" + day + "</span>天<span class='hour'>" + hour + "</span>小时<span class='mini'>" + minite + "</span>分<span class='sec'>" + second + "</span>秒");
		   
          }
		  else if (sysSecond == -1){}
		  else
		   {//剩余时间小于或等于0的时候，就停止间隔函数
             window.clearInterval(interValObj);
			 if(typeof callBackFunction == "function")callBackFunction($this,$message);
           }
      }
    }); 
  };
   //插件主要内容结束
    
  // 插件的defaults     
  $.fn.timeGo.defaults = {
	  mainSeconds:".remainSeconds",//剩余时间获取对象
	  mainTimeShow:".remainTime",//时间显示区域对象
	  message:'.message',//时间结束后的信息显示对象
	  callBackFunction:''
  };     
  
//套餐详情
  function superIMG2(node){
  	var img = node.find('#bigPIC'),
  		mask = node.find('#img_mask'),
  		po = jQuery('#po_bigView'),
  		superIMG = po.find('#superPIC'),
  		offset = node.offset(),
  		offset_x = offset.left,
  		offset_y = offset.top;
  	var superSRC = img.attr('data-superbig');
  	superIMG.attr('src',superSRC);
  	node.mousemove(function(event){
  		mask.css('display','block');
  		po.show();
  		var mousex = event.pageX - offset_x;
  		var mousey = event.pageY - offset_y;
  		var mask_x = mousex-50;
  		var mask_y = mousey-50;
  		if(mask_x<0)mask_x = 0;
  		if(mask_y<0)mask_y = 0;
  		if(mask_x+100 > 252)mask_x = 162;
  		if(mask_y+100 > 252)mask_y = 162;
  		mask.css({'left':mask_x,'top':mask_y});
  		po.css({'top':offset_y,'left':offset_x+262});
  		superIMG.css({'left':-mask_x*2,'top':-mask_y*2});
  	});
  	mask.mouseout(function(){
  		mask.css('display','');
  		po.hide();
  	});
  }
  
  
// 闭包结束 